# -*- coding: utf-8 -*-
"""
    Abs_models
    ~~~~~~~~~~~~~~

    Here are some utilities models for rpg. 
    
    :copyright: (c) 2011 by Arruda.
"""

from django.db import models
from django.utils.translation import ugettext_lazy as _

class AbsNamedModel(models.Model):    
    """
    A Class that has a name att.
    """
    nome = models.CharField(u"Nome",blank=False, null=False, max_length=250)
    
    class Meta:
        abstract = True

    def __unicode__(self):
        return self.nome
    

class RealTimeFramedModel(models.Model):
    """
    An abstract base class model that provides ``start``
    and ``end`` fields to record a timeframe.

    """
    start = models.DateTimeField(_('start'), null=False, blank=False)
    end = models.DateTimeField(_('end'), null=False, blank=False)
    real_start = models.DateTimeField(_('Real Start'), null=True, blank=True)
    real_end = models.DateTimeField(_('Real End'), null=True, blank=True)

    class Meta:
        abstract = True
    
    def clean(self):
        from django.core.exceptions import ValidationError
        if self.start >= self.end or self.real_start >= self.real_end:
            raise ValidationError(u'Data de inicio deve ser anterior a data de fim.')
